Conditions | 1 |
Paths | 1 |
Total Lines | 68 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /** |
||
29 | $( function () { |
||
30 | $( '#fileupload' ) |
||
31 | |||
32 | .on( 'change', function ( /* e, data */ ) { $( '#fileupload-results' ).empty(); } ) |
||
33 | .on( 'drop', function ( /* e, data */ ) { $( '#fileupload-results' ).empty(); } ) |
||
34 | |||
35 | .fileupload( { |
||
36 | dataType: 'json', |
||
37 | dropZone: $( '#fileupload-dropzone' ), |
||
38 | progressInterval: 100, |
||
39 | |||
40 | |||
41 | add: function ( e, data ) { |
||
42 | |||
43 | data.id = Date.now(); |
||
44 | |||
45 | var status = $('<li>') |
||
46 | .attr( 'id', data.id ) |
||
47 | .text( data.files[0].name ); |
||
48 | |||
49 | $( '#fileupload-results' ).append( status ); |
||
50 | |||
51 | data.formData = { |
||
52 | format: 'json', |
||
53 | action: 'upload', |
||
54 | token: $( this ).fileupload( 'option', 'token' ), |
||
55 | ignorewarnings: 1, |
||
56 | filename: data.files[ 0 ].name |
||
57 | }; |
||
58 | |||
59 | data.submit() |
||
60 | .success( function ( result /*, textStatus, jqXHR */ ) { |
||
61 | |||
62 | if ( result.error != undefined ) { |
||
63 | |||
64 | status.text( status.text() + " ERROR: " + result.error.info ).addClass( 'ful-error' ); |
||
65 | |||
66 | } else { |
||
67 | var link = $( '<a>' ); |
||
68 | link |
||
69 | .attr( 'href', mw.Title.makeTitle( mw.config.get( 'wgNamespaceIds' ).file, result.upload.filename ).getUrl() ) |
||
70 | .text( result.upload.filename ); |
||
71 | |||
72 | status |
||
73 | .addClass( 'ful-success' ) |
||
74 | .text( ' OK' ) |
||
75 | .prepend( link ); |
||
76 | } |
||
77 | |||
78 | } ) |
||
79 | .error( function ( /* jqXHR, textStatus, errorThrown */ ) { |
||
80 | status.text( status.text() + " ERROR" ).addClass( 'ful-error' ); |
||
81 | } ); |
||
82 | |||
83 | }, |
||
84 | |||
85 | progress: function (e, data) { |
||
86 | if ( data.loaded != data.total ) { |
||
87 | $( '#' + data.id ) |
||
88 | .text( data.files[0].name + ' ' + parseInt(data.loaded / data.total * 100, 10) + '%' ); |
||
89 | } |
||
90 | } |
||
91 | } ); |
||
92 | |||
93 | $( document ).bind( 'drop dragover', function ( e ) { |
||
94 | e.preventDefault(); |
||
95 | } ); |
||
96 | } ); |
||
97 | |||
99 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.